package com.fjs.blog.config;

import lombok.Data;

/**
 * Created by fjs72 on 2021/6/20 20:49
 */
@Data
public class Result {
    private static final long serialVersionUID = 1L;
    private String code;
    private String msg;
    private Object data;

    public static Result ok(){
        Result result = new Result();
        result.setCode("200");
        result.setMsg("操作成功");
        return result;
    }
    public static Result ok(Object data){
        Result result = new Result();
        result.setCode("200");
        result.setData(data);
        return result;
    }
    public static Result failed(String mes){
        Result result = new Result();
        result.setCode("400");
        result.setMsg(mes);
        result.setData(null);
        return result;
    }
    public static Result failed(Object data){
        Result result = new Result();
        result.setCode("40001");
        result.setMsg("操作失败");
        result.setData(data);
        return result;
    }
    public static Result fail(String msg) {
        return fail("400", msg, null);
    }
    public static Result fail(String msg, Object data) {
        return fail("400", msg, data);
    }

    public static Result fail(String code, String msg, Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
}
